<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page language="java" import="java.util.*,
								 com.kylin.common.Constants,
								 com.kylin.common.util.*,
                                 com.kylin.module.user.orm.User,
                                 org.apache.struts.util.LabelValueBean" %>
<%
response.addHeader("Cache-Control","no-stored");
response.addHeader("Pragma","no-cache");
response.setDateHeader("Expires",0);

		//String host = request.getHeader("Host");
		//response.addHeader("Host",request.getHeader("host").split(".")[0]);	

%>

<%
	java.util.Locale sessionLocale =(java.util.Locale)session.getAttribute(org.apache.struts.Globals.LOCALE_KEY);
	String acceptLanguage = request.getHeader("Accept-Language");
	String host = request.getHeader("Host");
	
	String languagel = "zh_CN";	

	String langcode = host.split("\\.")[0];

	if (langcode.equals("en")){
		languagel = "en_GB";
	}
	else if (langcode.equals("jp")){
		languagel = "ja_JP";
	}
	else if (langcode.equals("es")){
		languagel = "es_ES";
	}
	else if (langcode.equals("pt")){
		languagel = "pt_PT";
	}
	else if (langcode.equals("fr")){
		languagel = "fr_FR";
	}
	else if (langcode.equals("de")){
		languagel = "de_DE";
	}
	else if (langcode.equals("ru")){
		languagel = "ru_RU";
	}
	else if (langcode.equals("it")){
		languagel = "it_IT";
	}	
	else{
		langcode = "no";
	}
	
	if (langcode.equals("no")){
	
		if(sessionLocale ==null || 
		   !acceptLanguage.equals(session.getAttribute(Constants.USER_ACCEPTLANGUAGE))
		   ){
		    session.setAttribute(Constants.USER_ACCEPTLANGUAGE,acceptLanguage);
		    try{
		        String clang = acceptLanguage.split(",")[0];
		        clang = clang.replace('-','_');
			    for(int i=0;i<MemObjFactory.SysLocales.length ;i++){
			        String lv = MemObjFactory.SysLocales[i].toString();
			        if( lv.startsWith(clang.substring(0,2) ) ){
			            sessionLocale = MemObjFactory.SysLocales[i];
			        }
			        if(clang.equalsIgnoreCase(lv) ){
			            sessionLocale = MemObjFactory.SysLocales[i];
			            break;
			        }
			    }
		    }catch(Exception e){}
		    session.setAttribute(org.apache.struts.Globals.LOCALE_KEY,sessionLocale);
		}
	}
	if(sessionLocale ==null){
		//如果访问者浏览器语言未包括在系统支持的语言种类中，则选择系统支持的第一种语言做为缺省
		//sessionLocale = MemObjFactory.SysLocales[0];		
							
		sessionLocale=  UTool.getLocaleByLang(languagel);
		
		session.setAttribute(org.apache.struts.Globals.LOCALE_KEY,sessionLocale);
		
	}
	String basePath = request.getContextPath()+"/";
%>
